package com.gxaedu.shiro.service.impl;

import com.gxaedu.shiro.mapper.UserMapper;
import com.gxaedu.shiro.pojo.User;
import com.gxaedu.shiro.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
@SuppressWarnings("all")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private RedisTemplate<String,Object> jsonRedisTemplate;

    @Override
    public User findSimpleUser(String userName) {
        return userMapper.findSimpleUserByUserName(userName);
    }

    @Override
    public User findAllUser(String userName) {
        return userMapper.findByUserName(userName);
    }

    @Override
    public void saveUserToRedis(User user) {
        // 准备一个key
        String loginUserKey = "login:user:"+user.getUserName();
        jsonRedisTemplate.opsForValue().set(loginUserKey,user);
    }
}
